var currentL = 1, CurrentU = 10;
function init()
{
	var f = form('EncourageForm');
	for (var i = 0; i <  f.credit.options.length; i++)
	{
		if(encouragableCredits.indexOf(f.credit.options[i].value.toLowerCase()) == -1)
			f.credit.removeChild(f.credit.options[i]);
	}
	
	getCurrentSelected();
}

function getCurrentSelected()
{
	var f = form('EncourageForm');
	var index = encouragableCredits.indexOf(f.credit.value.toLowerCase());
	var s = encouragableCredits.substring(index + 8, encouragableCredits.indexOf(';', index));
	var arr = s.split(',');
	currentL = parseInt(arr[0]); CurrentU = parseInt(arr[1]);
	$('range').innerHTML = currentL + " ~ " + CurrentU;
	if (parseInt(f.total.value) < currentL)
		f.total.value = currentL;
	if (parseInt(f.total.value) > CurrentU)
		f.total.value = CurrentU;	
}
function onChangeCreditType()
{
	getCurrentSelected();
}
function onTotalBlur(obj)
{
	if (isNaN(obj.value))
	{
		alert('奖励数量必须是数字');
		obj.focus();
	}
	if (parseInt(obj.value) > CurrentU || parseInt(obj.value) < currentL)
	{
		alert('奖励数量必须在 ' + currentL + ' ~ ' + CurrentU + ' 之间');
		obj.focus();
	}
}

function onPost()
{
	if ($('deductprompt') != null)
	{
		var f = form('EncourageForm');
		var n = 1, u = 2, r = 3, v = 4;
		var creditindex = parseInt(f.credit.value.replace('Credit', ''));
		if (parseInt(f.total.value) > credits[creditindex][v])
		{
			alert('您当前帐户的' + credits[creditindex][n] + '只有' + credits[creditindex][v] + credits[creditindex][2]);
			return false;
		}
	}
	return true;
}